//
//  ByLoadingView.m
//  Homept_ios
//
//  Created by pro on 16/8/30.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ByLoadingView.h"

@implementation ByLoadingView


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {

        [self initViews];
    }
    
    return self;
}

- (void)initViews {
    
    _bgView = [[UIView alloc] initWithFrame:self.bounds];
    _bgView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
    _bgView.alpha = 0;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
    [_bgView addGestureRecognizer:tap];
    [self addSubview:_bgView];
    
    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    UIImage *gif = [UIImage sd_animatedGIFNamed:@"loading"];
    _imageView.image = gif;
    _imageView.backgroundColor = [UIColor clearColor];
    _imageView.center = CGPointMake(_bgView.width / 2, _bgView.height / 2);
    [_bgView addSubview:self.imageView];

}

- (void)show {
    
    [UIView animateWithDuration:0.3 animations:^{
        _bgView.alpha = 1;
    } completion:^(BOOL finished) {

    }];
    
}

- (void)hide {
 
    [UIView animateWithDuration:0.3 animations:^{
        self.bgView.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];

}

@end
